﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace RFPL
{
    class Global
    {
        public const string connectionString = "Data Source=TAI-PROG5;Initial Catalog=RFPL;Integrated Security=True";

        private static SqlConnection connection = null;

        public static SqlDataReader getDataReader(String command) 
        {
            connection = new SqlConnection(Global.connectionString);
            connection.Open();
            SqlCommand myCommand = connection.CreateCommand();
            myCommand.CommandText = command;
            SqlDataReader dataReader = myCommand.ExecuteReader();

            return dataReader;
        }

        public static SqlDataReader getDataReader(SqlCommand command)
        {
            connection = new SqlConnection(Global.connectionString);
            connection.Open();
            SqlCommand myCommand = command;
            SqlDataReader dataReader = myCommand.ExecuteReader();

            return dataReader;
        }

        public static int executeScalar(SqlCommand com) {

            int res = 0;

            connection = new SqlConnection(Global.connectionString);
            connection.Open();
            SqlCommand myCommand = com;
            res = (Int32) myCommand.ExecuteScalar();
            connection.Close();

            return res;
        }

        public static void closeConnection() {
            if (connection != null) {
                connection.Close();
            }
        }


    }
}
